// show date time
function nowdate(){
    document.getElementById("hktime").innerHTML = _fontStr[0] + "：<b>"+now.getDate() + _fontStr[1] + d2(now.getHours())+":"+d2(now.getMinutes())+":"+d2(now.getSeconds()+"</b>");
    now.setTime(now.getTime() + 1000);
    setTimeout("nowdate()",1000);
}

function countdown()
{
    if (timestap >= 0) {
      timediff = timestap;
      days = Math.floor(timediff / (60 * 60 * 24)); 
    	timediff -= days * (60 * 60 * 24);
    	hours = Math.floor(timediff / (60 * 60));
    	timediff -= hours * (60 * 60);	
    	mins = Math.floor(timediff / (60));
    	timediff -= mins * (60);	
    	secs = Math.floor(timediff);
        
      str = _fontStr[2] + " ";
      if (days > 0 ) str += "<b>" + days + "</b> " + _fontStr[3];
      if (hours > 0) str += "<b>" + hours + "</b> " + _fontStr[4];
      if (mins > 0) str += "<b>" + mins + "</b> " + _fontStr[5];
      str += "<b>" + secs + "</b> " + _fontStr[6];
      countdownstr.innerHTML =  str;
      setTimeout("countdown()",1000)
      timestap-=1;
      if (timestap==0) {
       My_Reload();
      }
    } else {
        countdownstr.innerHTML =  "<font color=red><b>" + _fontStr[7] + "！</b></font>";
    }
}

// create the table
// one bettype onlinebet 
$.fn.CreatTbl = function(redata, sId){
  var tblStr = '';
  var tblTotal = '';
  var tblTitle = '';
  var tblDataList = '';
  var numURL = _myHtml[3];
  //$(this).empty();
  
  eval("myObj = redata.bet" + sId + ";");
  if(myObj == undefined){$(this).html("-9, obj error"); return false; }
  
  tblTotal = '<td><a href="' + _myHtml[1] + '&bettype=' + sId + '">' + myObj.total + ' / ' + myObj.totalNum + '</a></td>';
  tblTitle = '<td>' + _fontStr[9] + '</td>';
  numURL = _myHtml[3] + '&bettype=' + sId;
  tblDataList += '<td style="vertical-align: top;">';
  if(myObj.totalNum > 0){
    tblDataList += '<table align="left" cellpadding="2" cellSpacing="1">';
    for(x in myObj.numbers){
      numURLTemp = numURL + '&numbers=' + myObj.numbers[x];
      tempClass = ' class="row' + (x % 2) + '" ';
      tblDataList += '<tr ' + tempClass + '><td class="numbers"><a href="' + numURLTemp + '">' + myObj.numbers[x] + '</a></td>';
      tblDataList += '<td class="amount"><a href="' + numURLTemp + '" style="color:#0000A8;font-weight:bold;">' + myObj.amount[x] + '</a></td></tr>';
    }
    tblDataList += '</table>';
    
  }else{
    tblDataList += '<center style="color:red">' + _fontStr[8] + '</center>';
  }
  tblDataList += '</td>';

  var titleTop = $("a[href='#tabs-" + sId + "']").text();
  tblStr = '<table width="100%" class="bet8Table">'
         + '<tr><th>' + titleTop + '</th></tr>'
         + '<tr class="bet8td1">' + tblTotal + '</tr>'
         + '<tr class="bet8td2">' + $().showRateTbl(myObj.rate) + '</tr>'
         + '<tr class="bet8td3">' + tblDataList + '</tr>'
         + '<table>'
         ;
  $(this).html(tblStr);
};

// top 20 onlinebet
$.fn.CreatTblTop20 = function(redata){
  var lengTh = redata.betArr.length;
  var tblStr = '';
  var tblTotal = '';
  var tblTitle = '';
  var tblDataList = '';
  var numURL = _myHtml[3];
  $(this).empty();
  for(i = 0; i < lengTh; i++){
    eval("myObj = redata.bet" + redata.betArr[i] + ";");
    tblTotal += '<td><a href="' + _myHtml[1] + '&bettype=' + redata.betArr[i] + '">' + myObj.total + ' / ' + myObj.totalNum + '</a></td>';
    tblTitle += '<td>' + _fontStr[9] + '</td>';
    numURL = _myHtml[3]+ '&bettype=' + redata.betArr[i];
    tblDataList += '<td style="vertical-align: top;">';
    if(myObj.totalNum > 0){
      tblDataList += '<table width="100%" align=center>';
      for(x in myObj.numbers){
        numURLTemp = numURL + '&numbers=' + myObj.numbers[x];
        tempClass = ' class="row' + (x % 2) + '" ';
         
        if(myObj.numbers[x].length > 17){
          numStrTemp = myObj.numbers[x].substr(0,18) + "<br />" + myObj.numbers[x].substr(18);
        }else{
          numStrTemp = myObj.numbers[x];
        }
         
        tblDataList += '<tr ' + tempClass + '><td class="numbers"><a href="' + numURLTemp + '">' + numStrTemp + '</a></td>';
        tblDataList += '<td class="amount"><a href="' + numURLTemp + '">' + myObj.amount[x] + '</a></td></tr>';
      }
      tblDataList += "</table>";
      
    }else{
      tblDataList += _fontStr[8];
    }
    tblDataList += '</td>';
  }
 
  tblStr = '<table width="100%" class="bet8Table">'
         + _myHtml[0]
         + '<tr class="bet8td1">' + tblTotal + '</tr>'
         + '<tr class="bet8td2">' + tblTitle + '</tr>'
         + '<tr class="bet8td3">' + tblDataList + '</tr>'
         + '<table>'
         ;
  $(this).html(tblStr);
};

// change the top menu
$.fn.getMyUrlSpan = function(){
  var mHref = $(this).attr("href").substr(1);
  var mDisk = $("#bet8MyDisk").val();
  var mSplit = $("#bet8MySplit").val();
  var sUrl = "op.php?op=agent&fp=" + mHref + "&lotto_id=" + _lotto_id + "&split=" + mSplit + "&disk=" + mDisk; 
  location.replace(sUrl);
};  



// get the data by sShow
// 0 : onlinebet
// 1 : unow
// 2 : bnow
// 3 : snow
$.fn.getBetData = function(sID, sType){
	var showId = sID;
	var betStr = "";
	var dataStr = "";
	var showRateFlag = "";
	var showDataN = "";  
	var mDisk = $("#bet8MyDisk").val();
  var mSplit = $("#bet8MySplit").val();
  var showTblStr = "#tabs-" + sID;
  
	if(showId == "top20"){
   betStr = _top20BetStr;
   showRateFlag = "0";
   showDataN = "20";
  }else{
   betStr = showId;
   showRateFlag = "1";
   showDataN = "1200";
  }
	dataStr = "&betStr=" + betStr
          + "&lotto_id=" + _lotto_id 
          + "&showRateFlag=" + showRateFlag
          + "&showDataN=" + showDataN
          + "&split=" + mSplit 
          + "&disk=" + mDisk
          ;
	$.getJSON('op.php?op=agent&fp=xmlGetOnlineBet8' + dataStr, function(redata){
     if(redata.errormsg == undefined) $(showTblStr).text("load Error");
     else if(redata.errormsg != "1") $(showTblStr).text(redata.errormsg);
     else{
       switch(sType){
        case 0:
          if(showId == 'top20'){ $(showTblStr).CreatTblTop20(redata); }
          else{ $(showTblStr).CreatTbl(redata, showId); }
          break;
       }
     }     
  });

};


// show rate table
$.fn.showRateTbl = function(rdata){
  var rate_list = '<table width="100%" cellpadding="1" cellSpacing="1" style="text-align:center">';
  var num = '';
  var ball = '';
  var g_numcolor = new Array("a","red","red","blue","blue","green","green","red","red","blue","blue","green","red","red","blue","blue","green","green","red","red","blue","green","green","red","red","blue","blue","green","green","red","red","blue","green","green","red","red","blue","blue","green","green","red","blue","blue","green","green","red","red","blue","blue","green");
  for (y=0; y< 5; y++) {
    rate_list += '<tr>';
    for (x = 1; x < 11 ; x++) {
      numidx = y * 10 + x;
      numArridx = numidx - 1;  
      num = d2(numidx);
      if ( num == '50'){ break; }
      rate = rdata[numArridx];
      ball = "background='image/" + g_numcolor[numidx] + ".gif'";
      rate_list += "<td class='ball_td' align='middle' " + ball + " bgColor='#c0d6eb' height='27' width='49'>"
		            + "<b>" + num + "</b></td><td bgColor='#e7ebef' nowrap> " + rate + "</td>";
	 }
	 rate_list += "</tr>";
  }
  rate_list += "</table>";
  return rate_list;
};




